
package domain.message;

import junit.framework.Assert;
import persistence.Persistent;
import persistence.PersistentTest;

/**
 * @author idan
 */
public class PostTest extends PersistentTest
{

	private static final int DEFAULT_POST_AUTHOR = 13 ;
	private static final String DEFAULT_TEXT = "test constructor" ;
	private static final int DEFAULT_POST_ID = 235 ;
	private static final int DEFAULT_PARENT_ID = 150 ;
	private static final String MODIFIED_POST_TEXT = "modified text" ;
	private static final String RANDOM_TEXT = "random text" ;

	Post post ;

	/**
	 * @see persistence.PersistentTest#setUp()
	 */
	@Override
	protected void setUp() throws Exception
	{
		super.setUp() ;
		this.post = new Post(PostTest.DEFAULT_POST_ID, PostTest.DEFAULT_TEXT, PostTest.DEFAULT_POST_AUTHOR,PostTest.DEFAULT_PARENT_ID);
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	@Override
	protected void tearDown() throws Exception
	{
		super.tearDown() ;
	}

	/**
	 * Test method for {@link domain.message.Post#Post(long, java.lang.String, long)}.
	 */
	public void testConstructor()
	{
		Assert.assertEquals(PostTest.DEFAULT_POST_ID, this.post.getId()) ;
		Assert.assertEquals(PostTest.DEFAULT_TEXT, this.post.getMessage()) ;
		Assert.assertEquals(PostTest.DEFAULT_POST_AUTHOR, this.post.getWriterId()) ;
	}

	/**
	 * Test method for {@link domain.message.Post#edit(java.lang.String)}.
	 */
	public void testSetText()
	{
		this.post.edit(PostTest.MODIFIED_POST_TEXT) ;
		Assert.assertEquals(PostTest.MODIFIED_POST_TEXT, this.post.getMessage()) ;
	}

	/**
	 * Test method for {@link domain.message.Post#edit(java.lang.String)}.
	 */
	public void testSetTextToEmptyString()
	{
		this.post.edit("") ;
		Assert.assertEquals("", this.post.getMessage()) ;
		this.testSetText() ;
	}

	/**
	 * Test method for {@link domain.message.Post#edit(java.lang.String)}.
	 */
	public void testSetTextTwice()
	{
		this.post.edit(PostTest.RANDOM_TEXT) ;
		Assert.assertEquals(PostTest.RANDOM_TEXT, this.post.getMessage()) ;
		this.testSetTextToEmptyString() ;
	}

	/**
	 * @see persistence.PersistentTest#createPersistent(long)
	 */
	@Override
	protected Persistent createPersistent(final long id)
	{
		return new Post(id, null, 0,1) ;
	}

}

